var MJModel           = require('./MJModel');
let roomAPI           = require('../../API/RoomAPI');
var MJProto           = require('./MJProto');
var RoomProto         = require('../../API/RoomProto');
var HallApi           = require('../../API/HallAPI');
var RoomAPI           = require('../../API/RoomAPI');
var enumeration       = require('../../Constant/enumeration');
var RoomMessageRouter = 'game.gameHandler.roomMessageNotify';
var GameMessageRouter = 'game.gameHandler.gameMessageNotify';
cc.Class({
	extends: cc.Component,
	properties: {
		layout: cc.Node,
		mjAtlas: cc.SpriteAtlas,
	},

	start: function () {
		let cards = [
			1, 2, 3, 4, 5, 6, 7, 8, 9,
			11, 12, 13, 14, 15, 16, 17, 18, 19,
			21, 22, 23, 24, 25, 26, 27, 28, 29,
			35
		];
		for (let i = 0; i < cards.length; ++i) {
			let node = new cc.Node;
			let sprite = node.addComponent(cc.Sprite);
			// let card = (cards[i] <= 9)? '0'+cards[i]:cards[i];
			let card = "down_"+Math.floor(cards[i]/10)+"_"+(cards[i]%10);
			sprite.spriteFrame = this.mjAtlas.getSpriteFrame(card);
			node.on(cc.Node.EventType.TOUCH_END, this.clickNode.bind(this, cards[i]));
			node.parent = this.layout;
		}
	},

	clickNode: function (card) {
		/* console.log('clickNode', card); */
		Global.NetworkManager.notify(GameMessageRouter, MJProto.gameGetCardNotify(card));
		this.layout.active = false;
	},

	onTestClick: function () {
		this.layout.active = true;
	},
});
